<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * 角色-权限关联表
 */
class CreateSysPermissionRoleTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //角色和权限多对多的关系表
        Schema::create('sys_permission_roles', function (Blueprint $table) {
            $table->unsignedInteger('perm_id')->comment('权限ID');
            $table->unsignedInteger('role_id')->comment('角色ID');
            //设置外键
            $table->foreign('perm_id')
                ->references('perm_id')
                ->on('sys_permissions')
                ->onDelete('cascade');
            $table->foreign('role_id')
                ->references('role_id')
                ->on('sys_roles')
                ->onDelete('cascade');
            $table->primary(['perm_id','role_id']);
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('sys_permission_roles');
    }
}
